﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_3
{
   public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "3.14159";
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            CalculateAndFormat();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            CalculateAndFormat();
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            CalculateAndFormat();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            UpdateFormat();
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            UpdateFormat();
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            UpdateFormat();
        }

        private void CalculateAndFormat()
        {
            double x, y;
            try
            {
                x = double.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("参数必须是数字！");
                textBox1.Text = "";
                textBox1.Focus();
                return;
            }

            if (radioButton1.Checked)
                y = Math.Sin(x);
            else if (radioButton2.Checked)
                y = Math.Cos(x);
            else
                y = Math.Tan(x);

            textBox2.Text = Math.Round(y, 2).ToString();
            UpdateFormat();
        }

        private void UpdateFormat()
        {
            FontStyle fontStyle = FontStyle.Regular;
            Color foreColor = Color.Black;

            if (checkBox1.Checked)
                fontStyle |= FontStyle.Bold;
            if (checkBox2.Checked)
                fontStyle |= FontStyle.Italic;
            if (checkBox3.Checked)
                foreColor = Color.Red;

            textBox2.Font = new Font(textBox2.Font.Name, textBox2.Font.Size, fontStyle);
            textBox2.ForeColor = foreColor;
        }
    }
}